package com.orange.delivery.business;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.orange.delivery.model.MarketBean;
import com.orange.delivery.technicalservice.exception.InvalidMarketException;
import com.orange.delivery.technicalservice.exception.InvalidQueryException;
import com.orange.delivery.technicalservice.exception.NotFoundException;
import com.orange.delivery.technicalservice.exception.TechnicalException;
import com.orange.delivery.technicalservice.tool.MultiValuedMap;

/**
 * business interface for market management
 * 
 * @author Clara
 */
public interface ManageMarketBusiness {

	/**
	 * Find all markets (from database AND mocked webservice)
	 * 
	 * @return Map of markets
	 * @throws NotFoundException
	 *             if no market found
	 */
	Map<Integer, MarketBean> findAllMarkets() throws NotFoundException, TechnicalException;

	/**
	 * Create market into database only (because webservice is mocked and static)
	 * 
	 * @param MarketBean
	 *            a market
	 * @return the id of the created market
	 * @throws InvalidMarketException
	 *             if market already exists
	 */
	Integer createMarket(MarketBean market) throws InvalidMarketException;

	/**
	 * Modify market into database only (because webservice is mocked and static)
	 * 
	 * @param MarketBean
	 *            a market
	 * @throws InvalidMarketException
	 *             if market update fails
	 * @throws NotFoundException
	 *             if market does not exist
	 */
	void modifyMarket(MarketBean market) throws InvalidMarketException, NotFoundException;

	/**
	 * Delete market into database only (because webservice is mocked and static)
	 * 
	 * @param idMarket
	 *            market id
	 * @throws InvalidMarketException
	 *             if market deletion fails
	 */
	void deleteMarket(Integer idMarket) throws InvalidMarketException;

	/**
	 * Consult market (from database AND mocked webservice)
	 * 
	 * @param idMarket
	 *            market id
	 * @throws NotFoundException
	 *             if market does not exist
	 */
	MarketBean getMarket(Integer idMarket) throws NotFoundException;

	/**
	 * find market (from database AND mocked webservice) which name contains parameter
	 * 
	 * @param name
	 *            String used to search for market names
	 * @return List of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	List<MarketBean> getMarketByName(String name) throws NotFoundException;

	/**
	 * count market (from database AND mocked webservice) which name contains parameter
	 * 
	 * @param name
	 *            String used to search for market names
	 * @return List of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	long getMarketCountByName(String name) throws NotFoundException;

	/**
	 * find market (from database AND mocked webservice) which name contains parameter. Results are paginated
	 * 
	 * @param name
	 *            String used to search for market names
	 * @param pageInfo
	 *            information on requested page
	 * @return Page of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	Page<MarketBean> getMarketByName(Pageable pageInfo, String name) throws NotFoundException;

	/**
	 * Obtain a page of markets matching criterias
	 * 
	 * @param pageInfo
	 *            informations on the requested page
	 * @param criteria
	 *            a Map of criterias
	 * @return the requested page
	 * @throws NotFoundException
	 * @throws InvalidQueryException
	 */
	Page<MarketBean> findMarketByCriteria(Pageable pageInfo, MultiValuedMap<String, String> criteria) throws NotFoundException,
			InvalidQueryException;

}